<template>
	<slot :controller="controller" :store="store" :model="model">
		<AppSDViewLayout :class="classNames" :openType="openType">
			<template
				v-if="!noViewCaption && model.showCaption"
				#viewHeaderContentLeft
			>
				<div class="view-header__caption">
					<slot
						name="ViewCaption"
						:controller="controller"
						:store="store"
						:model="model"
					>
						<AppCaptionBar
							:caption="model.caption"
							:title="model.title"
							:capPSLanguageRes="model.capPSLanguageRes"
							:titlePSLanguageRes="model.titlePSLanguageRes"
							:openType="openType"
						></AppCaptionBar>
					</slot>
					<slot
						name="ViewDataInfoBar"
						:controller="controller"
						:store="store"
						:model="model"
					>
						<AppDataInfoBar
							v-if="model.showDataInfoBar"
							:dataInfo="store.dataInfo"
						></AppDataInfoBar>
					</slot>
				</div>
			</template>
			<template v-if="store.toolbarItems.length > 0" #viewHeaderContentRight>
				<div class="view-header__toolbar">
					<slot
						name="ViewToolbar"
						:controller="controller"
						:store="store"
						:model="model"
						:actions="{ handleToolbarItemClick }"
					>
						<AppToolbar
							name="toolbar"
							mode="DEFAULT"
							:items="store.toolbarItems"
							:loading="store.loadingHelper.isLoading"
							@item-click="(name: string, event: MouseEvent, logic: any) => { handleToolbarItemClick(controller, name, event, logic) }"
						>
						</AppToolbar>
					</slot>
				</div>
			</template>
			<template #default>
				<slot
					name="Sys_departmentUsr0308173352Form"
					:controller="controller"
					:store="store"
					:model="model"
					:actions="{ handleCtrlInit, handleCtrlAction, handleCtrlDestroy }"
				>
					<Sys_departmentUsr0308173352Form
						:actions="{
							loadAction: 'Get',
							loadDraftAction: 'GetDraft',
							updateAction: 'Update',
							createAction: 'Create',
							removeAction: 'Remove',
							wfSubmitAction: 'WFSubmit',
							wfStartAction: 'WFStart',
						}"
						:openView="store.openView"
						:newView="store.newView"
						name="form"
						v-bind="model.ctrlParams.Sys_departmentform"
						:context="store.context"
						:viewParams="store.viewParams"
						:closeView="store.closeView"
						:pLoadingHelper="store.loadingHelper"
						:pViewCtx="store.viewCtx"
						@ctrl-init="(name:string, ability:any) => { handleCtrlInit(controller, name, ability) }"
						@ctrl-action="(name:string, action:any, data:any) => { handleCtrlAction(controller, name, action, data) }"
						@ctrl-destroy="(name:string, data:any) => { handleCtrlDestroy(controller, name, data) }"
					/>
				</slot>
			</template>
		</AppSDViewLayout>
	</slot>
</template>

<script lang="ts" setup>
// 基于template/src/views/{{appModules}}/{{pages@DEEDITVIEW}}/{{spinalCase page.codeName}}-base.vue.hbs生成
import { AppSDViewLayout } from '@components/layout/sd-view-layout';
import { AppToolbar } from '@components/widgets/toolbar';

import Sys_departmentUsr0308173352Form from '@widgets/sys-department/usr-0308173352-form/usr-0308173352-form.vue';
import {
	useProps,
	useBasic,
	useAction,
	useController,
} from './sys-department-usr-04-edit-view-hook';
import {
	IEvent,
	EditViewActionType,
	IEditViewAbility,
	IEditViewStore,
	IParam,
} from '@/core';

// 输入参数
const props = defineProps(useProps());

// 基础数据
const {
	model,
	getClassNames,
	useNavParamsBind,
	useEventBind,
	handleQuickSearch,
	handleToolbarItemClick,
	handleComponentAction,
	handleCtrlAction,
	handleCtrlInit,
	handleCtrlDestroy,
} = useBasic(props);

const emit = defineEmits<{
	(
		event: 'view-action',
		name: string,
		action: EditViewActionType,
		data: IParam[]
	): void;
	(event: 'view-init', name: string, data: IEditViewAbility): void;
	(event: 'view-mounted', name: string, data: IParam): void;
	(event: 'view-destroy', name: string, data: IParam): void;
}>();

const evt = useEventBind(emit);
const classNames = computed(() => {
	return getClassNames(props);
});

// 初始化控制器
const controller = useController(props, evt);

useNavParamsBind(controller, props);

const store: IEditViewStore = controller.getStore();

onMounted(() => {
	controller.viewMounted();
});

onUnmounted(() => {
	controller.viewDestroy();
});
</script>
